package com.etlmaster.executor.agent;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.client.RestTemplate;

import com.etlmaster.executor.scheduler.Proc;
import com.etlmaster.executor.scheduler.ScheduleStatus;
import com.etlmaster.executor.scheduler.utils.SubmitResult;

/**
 * @author Larry
 * @copyright Larry@etlMaster
 * @since 2017-09-10
 */
public abstract class Agents {

	private String host;
	private int maxThreadNum;
	private String id;
	private List<Proc> runningProcs= new ArrayList<Proc>();
	private int status;
	protected RestTemplate template = new RestTemplate();

	public Agents(String id,String host, int maxThreadNum) {
		this.id=id;
		this.setHost(host);
		this.setMaxThreadNum(maxThreadNum);
	}


	public abstract SubmitResult run(Proc proc);
	

	public abstract void stop();

	public int hasProc(Proc job) {
		for (Proc proc : getRunningProcs()) {
			if (proc.getProc_name().equalsIgnoreCase(job.getProc_name())
					&& proc.getCycle_id().equalsIgnoreCase(job.getCycle_id())) {
				return ScheduleStatus.sameProc;
			} else if (proc.getProc_name().equalsIgnoreCase(job.getProc_name())) {
				return ScheduleStatus.sameNameProc;
			}
		}
		return ScheduleStatus.noProc;
	}

	public List<Proc> getRunningProcs() {
		return runningProcs;
	}

	public void setRunningProcs(List<Proc> runningProcs) {
		this.runningProcs = runningProcs;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public int getMaxThreadNum() {
		return maxThreadNum;
	}

	public void setMaxThreadNum(int maxThreadNum) {
		this.maxThreadNum = maxThreadNum;
	}


	public int getStatus() {
		return status;
	}


	public void setStatus(int status) {
		this.status = status;
	}


	public String getId() {
		return id;
	}


	public void setId(String id) {
		this.id = id;
	}
}
